package 笔试真题;

import java.util.Scanner;

public class Baidu2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        for (int i = 0; i < 1<<30; i++) {
            deal(scanner.next());
        }
    }

    private static void deal(String value) {
        int len = value.length();
        int tempLen = len;
        char[] chars = value.toCharArray();
        boolean flag = false; // 头部是不是最后要去掉
        for (int i = 1; i < len; i++) {
            if (chars[i] == '0') {
                int j = i-1;
                for (; j >=0 ; j--) {
                    if(chars[j] == '1'){
                        chars[j] = '3';
                        if(j ==0) flag = true;
                    }else {
                        break;
                    }
                }
                if(j>=0) chars[j] = (char) ((int) chars[j ] - 1);
                tempLen = j+1;
                for (int k = j+1; k < len; k++) {
                    chars[k] = '3';
                }
                break;
            }
        }
        for (int i = 0; i < tempLen; i++) {
            if (chars[i] > '3') {
                for (int j = i; j < tempLen; j++) {
                    chars[j] = '3';
                }
                break;
            }
        }
        String s = flag ?  new String(chars).substring(1):new String(chars);
        System.out.println(s);
    }
}
